const config = require('../util/config')
const logger = require('log4js').getLogger()

module.exports = (req, res) => {
  require('../util/service').handlePost(req, res, (reqObj, resolve) => {
    if (config.domain == '') {
      require('../mng/chromeMng').loginJd().then(result => {
        resolve({
          result: 1,
          login: result
        })
      }, result => {
        resolve({
          result: -1,
          msg: '系统错误'
        })
      })
    } else if (config.domain == 'zoro.site') {
      require('../util/getHtml')({
        url: require('../mng/chromeServerMng').get() + 'loginJd.do',
        data: '{}'
      }).then(result => {
        var obj = JSON.parse(result)
        if (obj.result != 1)
          logger.debug('[' + __filename + ':' + __line + ']', result)
        resolve(JSON.parse(result))
      }, result => {
        logger.error('[' + __filename + ':' + __line + ']', result)
        resolve({
          result: -1,
          msg: '系统错误'
        })
      })
    }
  })
}